<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use app\admin\model;
class Courses extends Base {
    //课程表首页
    public function index()
    {
        $this->isLogin();
        $m = new model\Courses();
        $courses = $m->index();
        $this->assign('courses',$courses);

        return $this->fetch();

    }

    //课程删除
    public function delete(){
        $this->isLogin();
        $m = new model\Courses();
        $res = $m->cuorsesDelete();

        echo json_encode($res);

    }

    //课程修改界面
    public function update()
    {

        $this->isLogin();
        $m = new model\Courses();
        $cuorsesFind = $m->update();

        $data = "";
        $data .= "<table class=\"table table-bordered\" border=\"1\">";
        $data .= "<input class=\"courses_id\" type=\"hidden\" name=\"courses_id\" value=\"{$cuorsesFind['courses_id']}\">";
        $data .= "<tr>";
        $data .= "<th width=\"200px\">课程名字</th>";
        $data .= "<td><input class=\"courses_name\" type=\"text\" name=\"courses_name\" value=\"{$cuorsesFind['courses_name']}\"></td>";
        $data .= "</tr>";
        $data .= " <tr>";
        $data .= "<th>课程标题</th>";
        $data .= "<td><input class=\"courses_title\" type=\"text\" name=\"courses_title\" value=\"{$cuorsesFind['courses_title']}\"></td>";
        $data .= "</tr>";
        $data .= "<tr>";
        $data .= "<th>上传者名字</th>";
        $data .= "<td>{$cuorsesFind['user_name']}</td>";
        $data .= "</tr>";
        $data .= "<tr>";
        $data .= "<th>课程金额</th>";
        $data .= "<td><input class=\"courses_money\" type=\"text\" name=\"courses_money\" value=\"{$cuorsesFind['courses_money']}\"></td>";
        $data .= "</tr>";
        $data .= "</table>";
        $data .= "<span class=\"span layui-btn layui-btn-normal\">确认修改</span>";

        echo json_encode($data);
        exit;

//        $this->assign('cuorsesFind', $cuorsesFind);
//        return $this->fetch();
    }

    //课程修改
    public function cuorsesUpdate(){

        $this->isLogin();
        $m = new model\Courses();
        $res = $m->cuorsesUpdate();

        if($res>0){
            echo json_encode(1);
        }else{
            echo json_encode(0);
        }
        exit;

    }

    //图片上传
    public function uploadImg(){
        $this->isLogin();
        $m = new model\Courses();
        $res = $m->uploadImg();

        return json_encode($res);

    }

    //视频上传
    public function video(){
        $this->isLogin();
        $m = new model\Courses();
        $res = $m->video();
        return json_encode($res);

    }


    //课程新增界面
    public function insert(){
        $this->isLogin();


        $res = Db::table("courseclassify")->where("classify_del",0)->select();

        $this->assign("res",$res);
        return $this->fetch();

    }

    //课程新增
    public function cuorsesInsert(){
        $this->isLogin();
        $m = new model\Courses();
        $res = $m->cuorsesInsert();
        echo json_encode($res);
        exit;
    }

}
